import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { createStyleImportPlugin, AntdResolve } from 'vite-plugin-style-import'
import path from 'path'
// https://vitejs.dev/config/
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return defineConfig({
    // 这里对应 nginx 中的 location
    // base: env.VITE_APP_BASE_URL,
    plugins: [react(), createStyleImportPlugin({ resolves: [AntdResolve()] })],
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    },
    resolve: {
      alias: {
        '~': path.resolve(__dirname, 'src/modules'),
        '@': path.resolve(__dirname, 'src'),
        '@antv/x6': '@antv/x6/dist/x6.js',
        '@antv/x6-react-shape': '@antv/x6-react-shape/lib'

      }
    },
    server: {
      host: true,
      port: 8080,
      // open: true,
      proxy: {
        '/api/playbook': {
          target: env.VITE_APP_PROXY_TARGET + ':9081',
          changeOrigin: true, //是否跨域
          secure: false,
        },
        '/api/xbot/soar': {
          target: env.VITE_APP_PROXY_TARGET,
          changeOrigin: true, //是否跨域
          secure: false,
        },
        '/api/xbot': {
          target: env.VITE_APP_PROXY_TARGET + ':9082',
          changeOrigin: true, //是否跨域
          secure: false,
        },
      }
    },
    build: {
      terserOptions: {
        //打包后移除console和注释
        compress: {
          drop_console: true,
          drop_debugger: true
        }
      }
    }
  })
}
